package com.bootdo.staticmask.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.bootdo.staticmask.core.bean.ColumnProperty;
import com.bootdo.staticmask.core.oracle.OracleDataSource;
import com.bootdo.staticmask.dao.MaskOracleDao;
import com.bootdo.staticmask.domain.MaskOracleDO;
import com.bootdo.staticmask.service.MaskOracleService;

@Service
public class MaskOracleServiceImpl implements MaskOracleService {
	@Autowired
	private MaskOracleDao maskOracleDao;

	@Override
	public MaskOracleDO get(Integer oracleId) {
		return maskOracleDao.get(oracleId);
	}

	@Override
	public List<MaskOracleDO> list(Map<String, Object> map) {
		return maskOracleDao.list(map);
	}

	@Override
	public int count(Map<String, Object> map) {
		return maskOracleDao.count(map);
	}

	@Override
	public int save(MaskOracleDO maskOracle) {
		return maskOracleDao.save(maskOracle);
	}

	@Override
	public int update(MaskOracleDO maskOracle) {
		return maskOracleDao.update(maskOracle);
	}

	@Override
	public int remove(Integer oracleId) {
		return maskOracleDao.remove(oracleId);
	}

	@Override
	public int batchRemove(Integer[] oracleIds) {
		return maskOracleDao.batchRemove(oracleIds);
	}

	@Override
	public List<Map<String, String>> getTables(Integer id) {
		List<Map<String, String>> tableNames = null;
		try (OracleDataSource oracleDataSource = new OracleDataSource(maskOracleDao.get(id));) {
			tableNames = oracleDataSource.getTableNames();
		}
		return tableNames;
	}

	@Override
	public List<ColumnProperty> getColumns(Integer id, String owner, String tableName) {
		List<ColumnProperty> columns = null;
		try (OracleDataSource oracleDataSource = new OracleDataSource(maskOracleDao.get(id));) {
			columns = oracleDataSource.getTableColumns(owner, tableName);
		}

		return columns;
	}

}
